package niu_ke.lianbiao.bm01_反转链表;

/**
 * @author： YHSimon
 * @date： 2022-07-10 14:08
 */

class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class Solution {
    public ListNode ReverseList(ListNode head) {
        ListNode preHead=new ListNode(-1);
        while(head!=null){
            ListNode tmp=preHead.next;
            ListNode nextNode=head.next;
            preHead.next=head;
            head.next=tmp;
            head=nextNode;
        }
        return preHead.next;
    }
}
